﻿<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="P_PersonalDetails.Qualifications"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:P_PersonalDetails"
             xmlns:ref="clr-namespace:RefCodes;assembly=RefCodes"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="800">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="FormStyling.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:VisibilityConverter x:Key="IVisiblityConverter"/>
            <local:InverseVisibilityConverter x:Key="IInverseVisibilityConverter"/>
            <local:DeleteQualificationCommand x:Key="DeleteC"/>
            <local:AddQualificationCommand x:Key="AddC"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Border Style="{StaticResource BoxBorder}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Style="{StaticResource BoxHeading}">
                <Run Text="Qualifications"/>
            </TextBlock>
            <ItemsControl Grid.Row="1" ItemsSource="{Binding}"> 
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Style="{StaticResource BoxHeading}" FontSize="16" Text="{Binding Title}"/>
                            <Grid>
                                <StackPanel Visibility="{Binding HasExpiryDate, Converter={StaticResource IVisiblityConverter}}">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="2*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="4*"/>
                                            <ColumnDefinition Width="1*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0">Qualification Type</TextBlock>
                                        <TextBlock Grid.Column="1">Level</TextBlock>
                                        <TextBlock Grid.Column="2">Year Gained</TextBlock>
                                        <TextBlock Grid.Column="3">Expiry Date</TextBlock>
                                        <TextBlock Grid.Column="4">Note</TextBlock>
                                        <TextBlock Grid.Column="5" HorizontalAlignment="Center">Delete</TextBlock>
                                    </Grid>
                                    <ItemsControl ItemsSource="{Binding Qualifications}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="2*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                        <ColumnDefinition Width="4*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <ref:RefCodesComboBox x:Name="Type" CodeType="{Binding CategoryCT}" SelectedID="{Binding QTypeRC, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <ref:RefCodesComboBox Grid.Column="1" L2RefCode="{Binding QTypeRC, Mode=OneWay}" SelectedID="{Binding QLevelRCL2, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <TextBox Grid.Column="2" Text="{Binding YearAttained, Mode=TwoWay, ValidatesOnExceptions=True, TargetNullValue=''}"/>
                                                    <sdk:DatePicker Grid.Column="3" SelectedDate="{Binding RenewalDate, Mode=TwoWay, ValidatesOnExceptions=True}" />
                                                    <TextBox Grid.Column="4" Text="{Binding Comment, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <Button Grid.Column="5" CommandParameter="{Binding ID}" Style="{StaticResource Delete}" Command="{StaticResource DeleteC}"/>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>
                                <StackPanel Visibility="{Binding HasExpiryDate, Converter={StaticResource IInverseVisibilityConverter}}">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="2*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="0"/>
                                            <ColumnDefinition Width="4*"/>
                                            <ColumnDefinition Width="1*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0">Qualification Type</TextBlock>
                                        <TextBlock Grid.Column="1">Level</TextBlock>
                                        <TextBlock Grid.Column="2">Year Gained</TextBlock>
                                        <!--<TextBlock Grid.Column="3">Expiry Date</TextBlock>-->
                                        <TextBlock Grid.Column="4">Note</TextBlock>
                                        <TextBlock Grid.Column="5" HorizontalAlignment="Center">Delete</TextBlock>
                                    </Grid>
                                    <ItemsControl  ItemsSource="{Binding Qualifications}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="2*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                        <ColumnDefinition Width="0"/>
                                                        <ColumnDefinition Width="4*"/>
                                                        <ColumnDefinition Width="1*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <ref:RefCodesComboBox x:Name="Type" CodeType="{Binding CategoryCT}" SelectedID="{Binding QTypeRC, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <ref:RefCodesComboBox Grid.Column="1" L2RefCode="{Binding QTypeRC, Mode=OneWay}" SelectedID="{Binding QLevelRCL2, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <TextBox Grid.Column="2" Text="{Binding YearAttained, Mode=TwoWay, ValidatesOnExceptions=True, TargetNullValue=''}"/>
                                                    <!--<sdk:DatePicker Grid.Column="3" SelectedDate="{Binding RenewalDate}" />-->
                                                    <TextBox Grid.Column="4" Text="{Binding Comment, Mode=TwoWay, ValidatesOnExceptions=True}"/>
                                                    <Button Grid.Column="5" CommandParameter="{Binding ID}" Style="{StaticResource Delete}" Command="{StaticResource DeleteC}"/>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>
                            </Grid>
                            <Button Content="Add" CommandParameter="{Binding CodeType}" Command="{StaticResource AddC}" HorizontalAlignment="Left"/>
                        </StackPanel>                        
                    </DataTemplate>
                </ItemsControl.ItemTemplate>

            </ItemsControl>
        </Grid>
    </Border>
</UserControl>
